<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let ageArr = []
        for (let i = 1; i <= 5; i++) {
            let age = +prompt('请输入五个有效年龄（0-100之间）')
            if (age >= 0 && age <= 100) {
                ageArr.push(age)
            } else {
                alert('你输入的数字不合法，请重新输入')
                i = i - 1
            }
        }
        console.log(ageArr)

        //成年人的年龄
        let adultAge = []
        let sum = 0
        let max = ageArr[0]
        let min=ageArr[0]
        for (let i = 0; i < ageArr.length; i++) {
            // console.log(ageArr)
            if (ageArr > 18) {
                adultAge.push(adultAge[i])
            }
            // 计算所有人的总年龄
            sum += ageArr[i]
            if (ageArr[i] > max) {
                max = ageArr[i]
            }
            if (ageArr[i] < min) {
                min = ageArr[i]
            }
        }
        console.log(adultAge, '所有成年人的年龄')

        console.log(sum, '所有人的年龄总和')

        console.log(sum / ageArr.length, '所有人的平均年龄')


        console.log(max, '最大年龄')
        console.log(min, '最大年龄')










    </script>

</body>

</html>